package com.dhemery.mack.adapters.tests;

import static org.junit.Assert.*;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.junit.Test;

import com.dhemery.mack.adapters.NodeEditorInput;
import com.dhemery.mack.model.Node;

public class NodeEditorInputTests {

	@Test
	public void nameIsNodeName() {
		Node node = new Node("arbitrary name");
		NodeEditorInput input = new NodeEditorInput(node, null);

		assertEquals(node.getName(), input.getName());
	}

	@Test
	public void setsNodeName() {
		Node node = new Node("initial name");
		NodeEditorInput input = new NodeEditorInput(node, null);
		String newName = "new name";

		input.setName(newName);
		
		assertEquals(newName, node.getName());
	}

	@Test
	public void descriptionIsNodeDescription() {
		Node node = new Node("irrelevant node name");
		node.setDescription("arbitrary description");
		NodeEditorInput input = new NodeEditorInput(node, null);

		assertEquals(node.getDescription(), input.getDescription());
	}

	@Test
	public void setsNodeDescription() {
		Node node = new Node("irrelevant name");
		NodeEditorInput input = new NodeEditorInput(node, null);
		String newDescription = "new description";

		input.setDescription(newDescription);
		
		assertEquals(newDescription, node.getDescription());
	}

	@Test
	public void returnsGivenImageDescriptor() {
		ImageDescriptor expectedImageDescriptor = new FakeImageDescriptor("arbitrary name");
		NodeEditorInput input = new NodeEditorInput(null, expectedImageDescriptor );
		
		assertEquals(expectedImageDescriptor, input.getImageDescriptor());
	}

	@Test
	public void existsIsFalse() {
		NodeEditorInput input = new NodeEditorInput(null, null);

		assertFalse(input.exists());
	}

	@Test
	public void noAdapterForIEditorInputInterface() {
		assertNull(new NodeEditorInput(null, null).getAdapter(IEditorInput.class));
	}

	@Test
	public void noAdapterForIWorkbenchAdapterInterface() {
		assertNull(new NodeEditorInput(null, null).getAdapter(IWorkbenchAdapter.class));
	}

	@Test
	public void persistibleIsNull() {
		assertNull(new NodeEditorInput(null, null).getPersistable());
	}
}
